package com.mysteel.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * ProjectName: mail
 * ClassName: CorsConfiguration
 * Description:
 * date: 2020/12/18/018 11:25
 *
 * @author xiaochao
 */
@Configuration
public class CorsConfig {
    /**
     * CorsWebFilter 是spring boot为跨域请求封装的过滤器
     * @return
     */
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource urlCorsConfig = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        // 配置跨域
        configuration.addAllowedHeader("*");
        configuration.addAllowedMethod("*");
        configuration.addAllowedOrigin("*");
        configuration.setAllowCredentials(true);
        urlCorsConfig.registerCorsConfiguration("/**",configuration);
        return new CorsWebFilter(urlCorsConfig);
    }
}
